import { UserAccount, UserProfile } from "@/types/login";
import request from "../utils/request";

// 二维码生成接口

export function generateQRCode(key: string) {
  return request<{
    code: number;
    data: {
      qrurl: string;
      qrimg: string;
    };
  }>({
    url: "/login/qr/create",
    params: {
      key,
      qrimg: true,
      timerstamp: Date.now(),
    },
  });
}

export function generateQRCodeKey() {
  return request<{
    code: number;
    data: {
      code: number;
      unikey: string;
    };
  }>({
    url: "/login/qr/key",
    method: "get",
    params: {
      timerstamp: Date.now(),
    },
  });
}

export function chkQRLoginState(key: string) {
  return request<any>({
    url: "/login/qr/check",
    method: "get",
    params: {
      key,
      timerstamp: Date.now(),
    },
  });
}

export function getLoginStatus(cookie: string) {
  return request<{
    data: {
      account: UserAccount;
      code: number;
      profile: UserProfile;
    };
  }>({
    url: "/login/status",
    method: "get",
    params: {
      timerstamp: Date.now(),
      cookie,
    },
  });
}
